//
//  ViewController.swift
//  TMDatasourceLib
//
//  Created by chenchangqing on 11/07/2015.
//  Copyright (c) 2015 chenchangqing. All rights reserved.
//

import UIKit
import TMDatasourceLib

class ViewController: UIViewController {
    
    var userModelDataSourceProtocol: UserModelDataSourceProtocol!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        userModelDataSourceProtocol = UserModelDataSource.shareInstance()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    /**
     测试新浪登录
     
     - parameter sender:
     */
    @IBAction func testSinaLogin(sender: AnyObject) {
        
        userModelDataSourceProtocol.sinaLogin().subscribeNext({ (any:AnyObject!) -> Void in

            UIAlertView(title: "登录成功", message: "\(any)", delegate: nil, cancelButtonTitle: "确定").show()
        }, error: { (error:NSError!) -> Void in
            
            UIAlertView(title: "登录失败", message: "\(error.localizedDescription)", delegate: nil, cancelButtonTitle: "确定").show()
        })
    }
    
    /**
     测试腾讯登录
     
     - parameter sender:
     */
    @IBAction func testQQLogin(sender: AnyObject) {
        
        userModelDataSourceProtocol.qqLogin().subscribeNext({ (any:AnyObject!) -> Void in
            
            UIAlertView(title: "登录成功", message: "\(any)", delegate: nil, cancelButtonTitle: "确定").show()
        }, error: { (error:NSError!) -> Void in
                
            UIAlertView(title: "登录失败", message: "\(error.localizedDescription)", delegate: nil, cancelButtonTitle: "确定").show()    
        })
    }
}

